var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require("html-webpack-plugin");
//var ExtractTextPlugin = require('extract-text-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const VueLoaderPlugin = require('vue-loader/lib/plugin');
var config = {
	entry: {
		main: './src/main'
	},
	devtool: 'eval-source-map',
	output: {
		path: path.join(__dirname, './dist'),
		publicPath: '/',
		filename: 'js/[name].js'
	},
	resolve: {
      extensions: ['.js', '.vue', '.json'],
    },
	module: {
		rules: [
			{
				test: /\.css$/,
				use: [
					MiniCssExtractPlugin.loader,
					'css-loader?sourceMap',
					'postcss-loader?sourceMap',
				]

			},
			{
				test: /\.scss$/,
				use: [
					MiniCssExtractPlugin.loader,
					//'style-loader',
					'css-loader?sourceMap',
					{
						loader: 'postcss-loader',
						options: {
							ident: 'postcss',
							sourceMap:true,
							plugins: [
								require('autoprefixer')({
									'browsers': ['> 1%', 'last 2 versions']
								}),
							]
						}
					},
					{
						loader:'sass-loader',
						options:{
							sourceMap:true
						}
					}
				]
			},
			{
				test: /\.less$/,
				use: [
					MiniCssExtractPlugin.loader,
					'css-loader',
					'less-loader',
				]

			},
			{
				test: /\.vue$/,
				loader: 'vue-loader'
			},
			{
				test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/,
				loader: 'url-loader',
				options: {
					limit: 1024,
					name: 'images/[name].[hash:4].[ext]'
				}
			}
		]
	},
	plugins: [
		new MiniCssExtractPlugin({
			// Options similar to the same options in webpackOptions.output
			// both options are optional
			filename: 'css/common.css',
			chunkFilename: "[id].css"
		}),

		new HtmlWebpackPlugin({
			filename: 'index.html',
			template: './src/index.html',
			inject: true
		}),
		new VueLoaderPlugin()
	],
	devServer: {
	  disableHostCheck: true,
	  historyApiFallback: {
      rewrites: [
        { from: /.*/, to: path.posix.join('/', 'index.html') },
	  ],
    },
		proxy: {
			"/yourAPIContextPath": {
				target: 'http://backendhost:port/',		//后台地址和端口
			
				// pathRewrite: { '^/yourAPIContextPath': '' },
				changeOrigin: false,
			  /**
				本地模拟数据处理
				*/
				// onProxyReq(proxyReq, req, res) {
				// 	proxyReq.method = 'GET'

				// 	return proxyReq;
				// }
			}
		},

	},

}
module.exports = config;